import { ref } from "vue";
import { defineStore } from "pinia";

export const useBCardStore = defineStore("BCard", () => {
  // 学习经历
  const eduList = ref<myTypes.LearnList[]>([]);
  // 添加学习经历
  const seteduList = (info: myTypes.LearnList) => {
    if (info.name) {
      let arr = eduList.value;
      arr.push(info);
      eduList.value = arr;
    }
  };
  // 编辑学习经历
  const editEduList = (info: myTypes.LearnList) => {
    eduList.value = eduList.value.map((obj) => (obj.id === info.id ? info : obj));
  };
  // 工作经历
  const workList = ref<myTypes.WorkList[]>([]);
  // 添加工作经历
  const setworkList = (info: myTypes.WorkList) => {
    if (info.name) {
      let arr = workList.value;
      arr.push(info);
      workList.value = arr;
    }
  };
  // 编辑工作经历
  const editWorkList = (info: myTypes.LearnList) => {
    workList.value = workList.value.map((obj) => (obj.id === info.id ? info : obj));
  };
  // 编辑名片信息
  const editCardInfo = ref<myTypes.cardInfo>();
  const setEditCardInfo = (info: myTypes.cardInfo) => {
    editCardInfo.value = info;
  };
  // 修改学历经历和工作经历
  const editEduWorkInfo = ref<myTypes.LearnList>();
  const setEditEduWorkInfo = (info: myTypes.LearnList) => {
    editEduWorkInfo.value = info;
  };
  // 清空学习经历和工作经历
  const clearEditEduWorkInfo = () => {
    workList.value = [];
    eduList.value = [];
  };
  return {
    eduList,
    seteduList,
    workList,
    setworkList,
    editCardInfo,
    setEditCardInfo,
    editEduWorkInfo,
    setEditEduWorkInfo,
    editEduList,
    editWorkList,
    clearEditEduWorkInfo,
  };
});
